package com.lzcu.maoyan.mapreduce.mapreduce.mapper;

import com.lzcu.maoyan.mapreduce.mapreduce.unit.StockWritable;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.yarn.server.nodemanager.Context;

import java.io.IOException;

/**
 * @author WangLiang
 * @date `2024/4/24`
 */
public class StockMapper extends Mapper<NullWritable, StockWritable, Text, DoubleWritable> {

    @Override
    protected void map(NullWritable key, StockWritable value, Context context) throws IOException, InterruptedException {
        double[] recordings = value.getRecordings();
        double maxPrice = Double.MIN_VALUE;
        for (double recording : recordings) {
            if(maxPrice<recording){
                maxPrice=recording;
            }
        }
        context.write(new Text(value.getStockName()),new DoubleWritable(maxPrice));
    }
}
